package com.ibeeking.found.msg.rest.controller.v1;

import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.found.msg.rest.service.IMsgTypeService;
import com.ibeeking.found.msg.service.common.param.SmsTypeParam;
import com.ibeeking.found.msg.service.common.query.MsgTypePageQuery;
import com.ibeeking.found.msg.service.common.vo.MsgTypePageVO;
import com.ibeeking.found.msg.service.common.vo.MsgTypeVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @ClassName MsgTypeController控制器
 * @Description 消息场景类型
 * @Author ibeeking
 * @Date 2020-12-09 10:53
 **/
@RestController
@RequestMapping("/msg/msgType/v1")
public class MsgTypeController {

    @Resource
    private IMsgTypeService msgTypeServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息类型分页查询")
    @PostMapping(value = "/pageList")
    public Page<MsgTypePageVO> pageList(@RequestBody MsgTypePageQuery msgTypePageQuery) {
        return msgTypeServiceImpl.pageList(msgTypePageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "消息类型新增")
    @PostMapping(value = "/add")
    public Boolean add(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Insert.class) SmsTypeParam smsTypeParam) {
        smsTypeParam.setCreateBy(currentUser.getId());
        return msgTypeServiceImpl.add(smsTypeParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "消息类型修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Update.class) SmsTypeParam smsTypeParam) {
        smsTypeParam.setModifyBy(currentUser.getId());
        return msgTypeServiceImpl.modify(smsTypeParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息类型查看")
    @GetMapping(value = "/view/{id}")
    public MsgTypeVO view(@PathVariable("id") Long id) {
        return msgTypeServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "消息类型启用/禁用")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@LoginUser CurrentUser currentUser, @PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return msgTypeServiceImpl.changeStatus(id, status, currentUser.getId());
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "消息类型删除")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return msgTypeServiceImpl.del(id);
    }
}
